﻿<views:MvxWpfView 
	x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.ScheduleView"
	xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
	xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels;assembly=Sidvall.WorkItemManager.UI"
	xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
	xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
	xmlns:local="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Views"
	mc:Ignorable="d" 
	d:DesignHeight="500" d:DesignWidth="600">

	<views:MvxWpfView.Resources>
		<Converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
		<Converters:StringToVisibilityConverter x:Key="NotStringToVisibilityConverter" Not="True"/>
		<Converters:StringToBooleanConverter x:Key="NotStringToBooleanConverter" Not="True"/>
	</views:MvxWpfView.Resources>

	<Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:ScheduleViewModel}}">
		<TabControl>
			<TabItem Header="Generell">
				<ScrollViewer VerticalScrollBarVisibility="Auto">
					<StackPanel Grid.Row="1">
						<Controls:SubHeaderControl Margin="5,5,5,0" HeaderCaption="Duration" />

						<Grid Margin="5,5,5,0">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="130" />
								<ColumnDefinition Width="160" />
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>
							<Label Content="Start time"/>
							<xctk:DateTimePicker Grid.Column="1" Value="{Binding ActiveEntity.StartTime}" Format="Custom" FormatString="yyyy-MM-dd HH:mm:ss" />
							<Label Grid.Column="2" Content="End date"/>
							<DatePicker Grid.Column="3" FirstDayOfWeek="Monday" SelectedDate="{Binding ActiveEntity.EndDate}" />
						</Grid>

						<Controls:SubHeaderControl Margin="5,5,5,0" HeaderCaption="Summary" />

						<Grid Margin="5,5,5,0">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="130" />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>
							<Label Content="Description:"/>
							<TextBox Grid.Column="1" Text="{Binding ActiveEntity.Description, Mode=OneWay}" MinLines="3" MaxLines="3" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True" />
						</Grid>

						<Grid Margin="5,5,5,0">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="130" />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>
							<Label Content="Next Execution Time:"/>
							<TextBox Grid.Column="1" Text="{Binding ActiveEntity.NextExecutionTime, Mode=OneWay}" IsReadOnly="True" />
						</Grid>
					</StackPanel>
				</ScrollViewer>
			</TabItem>
			<TabItem Header="Frequency">
				<ScrollViewer VerticalScrollBarVisibility="Auto">
					<StackPanel>
						<Controls:SubHeaderControl Margin="5,5,5,0" HeaderCaption="Frequency" />

						<Grid Margin="5,5,5,0">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="130" />
								<ColumnDefinition Width="200" />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>

							<Label Content="Occurs:"/>
							<ComboBox Grid.Column="1" ItemsSource="{Binding ScheduleFrequencyTypes}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveEntity.ScheduleFrequencyTypeId}" />
						</Grid>

						<Grid Margin="5,5,5,0" Visibility="{Binding ActiveEntity.ScheduleFrequencyTypeId, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Daily}">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="130" />
								<ColumnDefinition Width="40" />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>
							<Label Content="Recurs every:"/>
							<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxScheduleFrequency}" Value="{Binding ActiveEntity.ScheduleFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
							<Label Grid.Column="2" Content="day(s)"/>
						</Grid>

						<StackPanel Visibility="{Binding ActiveEntity.ScheduleFrequencyTypeId, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Weekly}">
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Label Content="Recurs every:"/>
								<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxScheduleFrequency}" Value="{Binding ActiveEntity.ScheduleFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								<Label Grid.Column="2" Content="week(s) on"/>
							</Grid>
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition />
									<ColumnDefinition />
									<ColumnDefinition />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>

								<CheckBox Grid.Column="1" Content="Monday" IsChecked="{Binding ActiveEntity.Monday}" />
								<CheckBox Grid.Column="2" Content="Tuesday" IsChecked="{Binding ActiveEntity.Tuesday}" />
								<CheckBox Grid.Column="3" Content="Wednesday" IsChecked="{Binding ActiveEntity.Wednesday}" />
								<CheckBox Grid.Column="4" Content="Thursday" IsChecked="{Binding ActiveEntity.Thursday}" />
							</Grid>
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition />
									<ColumnDefinition />
									<ColumnDefinition />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>

								<CheckBox Grid.Column="1" Content="Friday" IsChecked="{Binding ActiveEntity.Friday}" />
								<CheckBox Grid.Column="2" Content="Saturday" IsChecked="{Binding ActiveEntity.Saturday}" />
								<CheckBox Grid.Column="3" Content="Sunday" IsChecked="{Binding ActiveEntity.Sunday}" />
							</Grid>
						</StackPanel>

						<StackPanel Visibility="{Binding ActiveEntity.ScheduleFrequencyTypeId, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Monthly}">
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Label Content="Recurs every:"/>
								<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxScheduleFrequency}" Value="{Binding ActiveEntity.ScheduleFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								<Label Grid.Column="2" Content="month(s) on"/>
							</Grid>
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="110" />
									<ColumnDefinition Width="20" />
									<ColumnDefinition Width="200" />
									<ColumnDefinition Width="20" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>

								<Grid Visibility="{Binding ActiveEntity.MonthFrequencyTypeId, Converter={StaticResource NotStringToVisibilityConverter}, ConverterParameter=Day}">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="70" />
										<ColumnDefinition Width="40" />
									</Grid.ColumnDefinitions>
									<Label Content="The"/>
									<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxMonthFrequency}" Value="{Binding ActiveEntity.MonthFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								</Grid>
								<ComboBox Grid.Column="2" ItemsSource="{Binding MonthFrequencyTypes}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveEntity.MonthFrequencyTypeId}" />
								<Grid Grid.Column="4" Visibility="{Binding ActiveEntity.MonthFrequencyTypeId, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Day}">
									<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxMonthFrequency}" Value="{Binding ActiveEntity.MonthFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								</Grid>
							</Grid>
						</StackPanel>

						<Controls:SubHeaderControl Margin="5,5,5,0" HeaderCaption="Daily Frequency" />

						<StackPanel IsEnabled="{Binding ActiveEntity.ScheduleFrequencyTypeId, ConverterParameter=Onetime, Converter={StaticResource NotStringToBooleanConverter}}">
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="200" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>

								<Label Content="Occurs:"/>
								<ComboBox Grid.Column="1" ItemsSource="{Binding DayFrequencyTypes}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveEntity.DayFrequencyTypeId}" />
							</Grid>
							<Grid Margin="5,5,5,0" Visibility="{Binding ActiveEntity.DayFrequencyTypeId, ConverterParameter=EveryHour, Converter={StaticResource StringToVisibilityConverter}}">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Label Content="Recurs every:"/>
								<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxDayFrequency}" Value="{Binding ActiveEntity.DayFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								<Label Grid.Column="2" Content="hour(s)"/>
							</Grid>
							<Grid Margin="5,5,5,0" Visibility="{Binding ActiveEntity.DayFrequencyTypeId, ConverterParameter=EveryMinute, Converter={StaticResource StringToVisibilityConverter}}">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Label Content="Recurs every:"/>
								<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxDayFrequency}" Value="{Binding ActiveEntity.DayFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								<Label Grid.Column="2" Content="minute(s)"/>
							</Grid>
							<Grid Margin="5,5,5,0" Visibility="{Binding ActiveEntity.DayFrequencyTypeId, ConverterParameter=EverySecond, Converter={StaticResource StringToVisibilityConverter}}">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="40" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<Label Content="Recurs every:"/>
								<xctk:IntegerUpDown Grid.Column="1" Minimum="1" Maximum="{Binding ActiveEntity.MaxDayFrequency}" Value="{Binding ActiveEntity.DayFrequency}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
								<Label Grid.Column="2" Content="second(s)"/>
							</Grid>
							<Grid Margin="5,5,5,0">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="130" />
									<ColumnDefinition Width="100" />
									<ColumnDefinition Width="20" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>

								<Label Content="Starting at:"/>
								<xctk:TimePicker Grid.Column="1" Value="{Binding ActiveEntity.DayStartTime}" ClipValueToMinMax="True" EndTime="23:59:59" FormatString="HH:mm:ss" Format="Custom" />

								<Grid Grid.Column="3" Visibility="{Binding ActiveEntity.DayFrequencyTypeId, ConverterParameter=Onetime, Converter={StaticResource NotStringToVisibilityConverter}}">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="Auto" />
										<ColumnDefinition Width="100" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>

									<Label Grid.Column="0" Content="Ending at:"/>
									<xctk:TimePicker Grid.Column="1" Value="{Binding ActiveEntity.DayEndTime}" ClipValueToMinMax="True" EndTime="23:59:59" FormatString="HH:mm:ss" Format="Custom" />
								</Grid>
							</Grid>
						</StackPanel>
					</StackPanel>
				</ScrollViewer>
			</TabItem>
		</TabControl>
	</Grid>
</views:MvxWpfView>
